package com.ruoyi.info.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.domain.CmsCaptcha;
import com.ruoyi.info.service.ICmsCaptchaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 验证码-Controller
 * 
 * @author xwj
 * @date 2023-07-17
 */
@Controller
@RequestMapping("/captcha/captcha")
public class CmsCaptchaController extends BaseController
{
    private String prefix = "captcha/captcha";

    @Autowired
    private ICmsCaptchaService cmsCaptchaService;

    @GetMapping()
    public String captcha()
    {
        return prefix + "/captcha";
    }

    /**
     * 查询验证码-列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsCaptcha cmsCaptcha)
    {
        startPage();
        List<CmsCaptcha> list = cmsCaptchaService.selectCmsCaptchaList(cmsCaptcha);
        return getDataTable(list);
    }

    /**
     * 导出验证码-列表
     */
    @Log(title = "验证码-", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsCaptcha cmsCaptcha)
    {
        List<CmsCaptcha> list = cmsCaptchaService.selectCmsCaptchaList(cmsCaptcha);
        ExcelUtil<CmsCaptcha> util = new ExcelUtil<CmsCaptcha>(CmsCaptcha.class);
        return util.exportExcel(list, "验证码-数据");
    }

    /**
     * 新增验证码-
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存验证码-
     */
    @Log(title = "验证码-", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsCaptcha cmsCaptcha)
    {
        return toAjax(cmsCaptchaService.insertCmsCaptcha(cmsCaptcha));
    }

    /**
     * 修改验证码-
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsCaptcha cmsCaptcha = cmsCaptchaService.selectCmsCaptchaById(id);
        mmap.put("cmsCaptcha", cmsCaptcha);
        return prefix + "/edit";
    }

    /**
     * 修改保存验证码-
     */
    @Log(title = "验证码-", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsCaptcha cmsCaptcha)
    {
        return toAjax(cmsCaptchaService.updateCmsCaptcha(cmsCaptcha));
    }

    /**
     * 删除验证码-
     */
    @Log(title = "验证码-", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsCaptchaService.deleteCmsCaptchaByIds(ids));
    }
}
